//
//  AnswerTitleTableViewCell.m
//  SafeFoodManagerDemo
//
//  Created by ios-1 on 2018/3/7.
//  Copyright © 2018年 bob. All rights reserved.
//

#import "AnswerTitleTableViewCell.h"

@implementation AnswerTitleTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)refreshData:(QuestionDetailModel*)detailModel;
{
    
    NSString *itemtypeStr = @"";
    if(detailModel.data.itemType == 1)
    {
        itemtypeStr = @"问答题";
    }else if (detailModel.data.itemType == 2)
    {
        itemtypeStr = @"单选题";
    }else if (detailModel.data.itemType == 3)
    {
        itemtypeStr = @"多选题";
    }else if (detailModel.data.itemType == 4)
    {
        itemtypeStr = @"判断题";
    }
    //只有考官 或者考官封卷后考生能看标准答案
    if([LoginStatuesModel getUserType] == 4 || detailModel.data.isMark)
    {
        self.AnswerTitleLab.text = [NSString stringWithFormat:@"【%@】%@（%zd分） ",itemtypeStr,detailModel.data.itemText,detailModel.data.score];
        
        // 创建一个富文本
        NSMutableAttributedString *attri =     [[NSMutableAttributedString alloc] initWithString:self.AnswerTitleLab.text];
        NSTextAttachment *attch = [[NSTextAttachment alloc] init];
        // 表情图片
        attch.image = [UIImage imageNamed:@"answer问号"];
        
        // 设置图片大小
        attch.bounds = CGRectMake(15, -5, 20, 20);
        
        // 创建带有图片的富文本
        NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
        [attri appendAttributedString:string]; //在文字后面添加图片
        
        //在文字下标第几个添加图片  0就是文字前面添加图片
        // [attri insertAttributedString:string atIndex:0];
        // 用label的attributedText属性来使用富文本
        // 实例化的lable.attributedText = attri;
        self.AnswerTitleLab.attributedText = attri;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(click)];
        self.AnswerTitleLab.userInteractionEnabled = YES;
        [self.AnswerTitleLab addGestureRecognizer:tap];
    }
    else{
        self.AnswerTitleLab.text = [NSString stringWithFormat:@"【%@】%@（%zd分） ",itemtypeStr,detailModel.data.itemText,detailModel.data.score];
    }
}

- (void)click
{
    if(self.titleClickBlock)
    {
        self.titleClickBlock();
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
